<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Class_Assess extends AdminController
{

	function __construct()
	{
		parent::__construct();
		$this->sidebar = "Index";
		$this->load->model("Class_model");
		$this->load->library('ProjectService/attend_service');
		$this->load->model("Attend_model");
		$this->load->model("Attend_img_model");
		$this->load->library('ProjectService/class_service');
		$this->load->model("Admin_model");
		$this->load->library("ProjectService/table_service");
		$this->load->library("ProjectService/admin_service");
		$this->load->library('ProjectService/upload_img_service');

		$this->date = date('Y-m-d', time());
		$this->month = date('m', time());//当前学期
		// $this->month = date('m', '1706252919');//当前学期
		// $this->month = date('m', '1661740784');
	}

	//督导听课
	function attendAdd($type, $attend_id, $teacher_id = false)
	{

		if ($teacher_id) {
			$data = $this->Admin_model->get_single(array('id' => $teacher_id));
			$data['teacher_detail'] = $data;
		}



		if ($attend_id == 0) {
			$data = $this->attend_service->getAttendData(0, false, false, $type);
			if (!isset($data['attend_record'][0]['time']) || $data['attend_record'][0]['time'] == '') {
				$data['attend_record'][0]['time'] = date('Y-m-d H:i:s', time());
			}

			if (!isset($data['attend_record'][0]['commentary']) || $data['attend_record'][0]['commentary'] == '') {
				$data['attend_record'][0]['commentary'] = '';
			}

			// if(!isset($data['attend_img'][0]['img']) || $data['attend_img'][0]['img'] == ''){
			// 	  $data['attend_img'][0]['img'] = '';
			// }

			$data['is_add'] = 0;
			// $date = date('Y-m-d', time());
			// $month = date('m', time());
			if ($this->month == 9 || $this->month == 10 || $this->month == 11 || $this->month == 12 || $this->month == 1) {
				if ($this->month == 1) {
					$year = date('Y', time()) - 1;
					$year_last = date('Y', time());
				} else {
					$year = date('Y', time());
					$year_last = date('Y', time()) + 1;
				}
				// $year=date('Y',time());
				// $year_last=date('Y',time())+1;
				$data['class_detail']['semester'] = '第一学期';
				$data['class_detail']['academic_year'] = strval($year . '-' . $year_last);
			} else if ($this->month == 2 || $this->month == 3 || $this->month == 4 || $this->month == 5 || $this->month == 6 || $this->month == 7 || $this->month == 8) {
				$year = date('Y', time()) - 1;
				$year_last = date('Y', time());
				// $semester = '第一学期';
				$data['class_detail']['academic_year'] = strval($year . '-' . $year_last);
				$data['class_detail']['semester'] = '第二学期';
			}

			$data['is_show'] = 0;
			$data['can_save'] = 1; //保存按钮
			$data['can_submit'] = 1; //提交按钮

		} else {
			$data = $this->attend_service->getAttendData($attend_id, false, false, $type);
			// $data['attend']['listen_time'] = $data['attend']['listen_time']==0?'':date('Y-m-d ', $data['attend']['listen_time']);
			$data['class_list'] = $this->getClass($data['attend']['teacher_code']);

			//判断课程名称是下拉框还是输入框
			$aa = array();
			foreach ($data['class_list'] as $ka => $va) {
				if ($data['attend']['class_name'] != $va['name']) {
					$aa[$ka] = 1;
				}
			}
			if (count($aa) == count($data['class_list'])) {
				$data['is_show'] = 1;
			} else {
				$data['is_show'] = 0;
			}

			$data['is_add'] = $attend_id;
			if ($data['attend']['type'] == AttendType::School[XPHEnum::Value]) {
				$data['role_index'] = 0;
			} else if ($data['attend']['type'] == AttendType::Unit[XPHEnum::Value]) {
				$data['role_index'] = 1;
			}

			if ($data['attend']['listen_id'] == getSess()['id'] && $data['attend']['status'] == AttendStatus::Save[XPHEnum::Value]) {
				$data['can_submit'] = 1;
				$data['can_save'] = 1;
			} else {
				$data['can_submit'] = 0;
				$data['can_save'] = 0;
			}
		}

		//获取授课教师列表
		$list = $this->admin_service->getAllAdmin();
		foreach ($list as $key => $value) {
			$arr[$key]['id'] = $value['id'];
			$arr[$key]['usercode'] = $value['usercode'];
			$arr[$key]['username'] = $value['username'];
			$arr[$key]['dept_name'] = $value['dept_name'];
		}


		$data['teacher'] = $arr;

		// 获取开课单位
		// $date=date('Y-m-d',time());			
		// $month=date('m',time());
		// if($month==9 || $month==10 || $month==11 || $month==12){
		// 	$year=date('Y',time());
		// 	$year_last=date('Y',time())+1;
		// 	$default_academic_year=strval($year.'-'.$year_last);			
		// }else if($month==1 || $month==2 || $month==3 || $month==4 || $month==5 || $month==6 || $month==7 || $month==8){
		// 	$year=date('Y',time())-1;
		// 	$year_last=date('Y',time());
		// 	$default_academic_year=strval($year.'-'.$year_last);	
		// }
		// $connar['items']="course_units";
		// $connar['where']=$this->sqlLikeEscape('elective_lesson_no like "%??%" and course_units is not null',array($default_academic_year));
		// $connar['groupby']="course_units";
		// $data['course_units']=array_column($this->Class_model->get_list_full($connar), 'course_units');
		// foreach($data['course_units'] as $k=>$v){
		// 	if(!$v){
		// 		unset($data['course_units'][$k]);
		// 	}
		// }
		// $data['course_units'] = array_merge($data['course_units']);

		//获取开课单位
		$data['course_units'] = (new AdminDeptList)->getRemark()[1];

		//获取教师职称    
		$titlelist = array();
		foreach ((new Title)->getAll() as $k => $v) {
			$titlelist[$k]['key'] = $v[XPHEnum::Value];
			$titlelist[$k]['value'] = $v[XPHEnum::Caption];
		}
		$data['teacher_title'] = $titlelist;
		//获取教师职称    
		$teachers_attribute_list = array();
		foreach ((new TeachersAttribute)->getAll() as $k => $v) {
			$teachers_attribute_list[$k]['key'] = $v[XPHEnum::Value];
			$teachers_attribute_list[$k]['value'] = $v[XPHEnum::Caption];
		}

		$data['teachers_attribute_list'] = $teachers_attribute_list;

		//获取新版课程类型 
		$this->load->model("Select_model");
		$result = $this->Select_model->get_list(array('type' => SelectType::CourseType[XPHEnum::Value], 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));
		$data['class_type'] = array();
		foreach ($result as $k => $v) {
			if ($type == ($k + 1)) {
				array_push($data['class_type'], trim($v['option']));
			}
		}

		// if($type == 1){
		// 	$result = $this->Select_model->get_list(array('type' => SelectType::CourseType[XPHEnum::Value],'option'=>'理论课', 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));
		// 	$data['class_type'] = array();
		// 	foreach ($result as $k => $v) {
		// 		array_push($data['class_type'], trim($v['option']));
		// 	}

		// }else{
		// 	$result = $this->Select_model->get_list(array('type' => SelectType::CourseType[XPHEnum::Value],'option'=>'实训课', 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));
		// 	$data['class_type'] = array();
		// 	foreach ($result as $k => $v) {
		// 		array_push($data['class_type'], trim($v['option']));
		// 	}
		// }

		//获取旧版课程类型
		$result1 = $this->Select_model->get_list(array('type' => 11, 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));
		$data['class_type_old'] = array();
		foreach ($result1 as $k => $v) {
			array_push($data['class_type_old'], trim($v['option']));
		}


		//获取听课类型
		$result1 = $this->Select_model->get_list(array('type' => SelectType::ListenType[XPHEnum::Value], 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));
		$data['ListenType'] = array();
		foreach ($result1 as $k => $v) {
			array_push($data['ListenType'], trim($v['option']));
		}

		//督导身份
		// $data['AttendType'] = $this->table_service->getAttendType(getSess()['id']);
		// var_dump($data['AttendType']);
		$data['AttendType'] = array();
		$role = explode(',', getSess()['sub_role_id']);
		array_push($role, getSess()['role_id']);
		$role = array_merge(array_filter($role));
		
		//超级管理员
		if (in_array(WebRole::Admin[XPHEnum::Value], $role)) {
			$data['AttendType'] = $this->table_service->getAttendType(getSess()['id']);
		}else{
			if (in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)) {
				// unset($data['type'][0]);
				// array_splice($data['type'],0,1);  
				array_push($data['AttendType'], array('key' => AttendType::School[XPHEnum::Value], 'value' => AttendType::School[XPHEnum::Caption]));
			}
			if (in_array(WebRole::UnitSupervisor[XPHEnum::Value], $role)) {
				// unset($data['type'][1]);
				// array_splice($data['type'],1,1);  
				array_push($data['AttendType'], array('key' => AttendType::Unit[XPHEnum::Value], 'value' => AttendType::Unit[XPHEnum::Caption]));
			}
			if (in_array(WebRole::OutsideSupervisor[XPHEnum::Value], $role)) {
				// unset($data['type'][1]);
				// array_splice($data['type'],1,1);  
				array_push($data['AttendType'], array('key' => AttendType::Outside[XPHEnum::Value], 'value' => AttendType::Outside[XPHEnum::Caption]));
			}
			if (in_array(WebRole::Teacher[XPHEnum::Value], $role)) {
				array_push($data['AttendType'], array('key' => AttendType::Teacher[XPHEnum::Value], 'value' => AttendType::Teacher[XPHEnum::Caption]));
			}
	
			if (in_array(WebRole::SchoolLeader[XPHEnum::Value], $role) || in_array(WebRole::UnitLeader[XPHEnum::Value], $role) || in_array(WebRole::CadreUnitLeader[XPHEnum::Value], $role)) {
				array_push($data['AttendType'], array('key' => AttendType::UnitLeader[XPHEnum::Value], 'value' => AttendType::UnitLeader[XPHEnum::Caption]));
			}
	
			if (in_array(WebRole::MajorUnitLeader[XPHEnum::Value], $role)) {
				array_push($data['AttendType'], array('key' => AttendType::MajorUnitLeader[XPHEnum::Value], 'value' => AttendType::MajorUnitLeader[XPHEnum::Caption]));
			}

		}

		if($attend_id != 0){
			//判断编辑的时候听课身份不存在的追加进去
			$types = array_column($data['AttendType'],'key');
			if(!in_array($data['attend']['type'],$types)){
				array_push($data['AttendType'], array('key' => $data['attend']['type'], 'value' =>(new AttendType)->show($data['attend']['type'])));
			}
		}

		// if($data['AttendType'][0]['key']==AttendType::Teacher[XPHEnum::Value] && count($data['AttendType'])==1){
		// 	$data['can_submit']=0;
		// }else{
		// 	$data['can_submit']=1;
		// }


		if (in_array(WebRole::SchoolLeader[XPHEnum::Value], $role) || in_array(WebRole::UnitLeader[XPHEnum::Value], $role) || in_array(WebRole::CadreUnitLeader[XPHEnum::Value], $role)) {
			$data['is_mr_ldgb'] = 1;
		 }else{
			$data['is_mr_ldgb'] = 0;
		 }


		if ($type == 1) {
			$data['title'] = "督导听课(理论课)";
			$data['cc_type'] = $type;

			$this->load->view('admin/attendAdd', $data);
		} else if ($type == 2)  {
			$data['title'] = "督导听课(实训、实验课)";
			$data['cc_type'] = $type;
			$this->load->view('admin/attendsAdd', $data);
		}else if ($type == 3)  {
			$data['title'] = "督导听课(思政课)";
			$data['cc_type'] = $type;
			$this->load->view('admin/attend3Add', $data);
		}else if ($type == 4)  {
			$data['title'] = "督导听课(体育课)";
			$data['cc_type'] = $type;
			$this->load->view('admin/attend4Add', $data);
		}else{
			$data['title'] = "督导听课(理论课)";
			$data['cc_type'] = $type;
			$this->load->view('admin/attendAdd', $data);
		}
	}



	//保存督导听课
	function saveAttend($attend_id = 0)
	{

		$is_submit = $this->Attend_model->get_single(array('id' => $attend_id));
		if ($is_submit['status'] == AttendStatus::Submit[XPHEnum::Value]) {
			exit(retJson('已提交无法修改', false));
		}

		$formdata = $_POST;

		// var_dump($formdata);

		//教师听课只能保存,无法提交
		if ($formdata['role'] == AttendType::Teacher[XPHEnum::Value] && $formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {
			exit(retJson('教师听课无法提交', false));
		}

		$array_arr = explode(",", $_POST['teacher_name']);


		$formdata['teacher_code'] = isset($array_arr[0])?$array_arr[0]:'';
		$formdata['teacher_name'] =isset($array_arr[1])? $array_arr[1]:'';

		$data = $this->Class_model->get_single(array('id' => $formdata['class_id']));
		$data1 = $this->Admin_model->get_single(array('id' => $formdata['teacher_id']));
		$data2 = $this->Admin_model->get_single(array('id' => getSess()['id']));
		$class_id = $data['id'];

		// var_dump($data);
		// if($formdata['sub_role']==0){
		// 	$Error['error']=3;
		// 	exit(retJson('请选择反馈身份！',false,$Error));
		// }else{
		// 	$type=$formdata['sub_role'];
		// }		
		// if($type==WebRole::SchoolSupervisor[XPHEnum::Value]){
		// 	$type=AttendType::School[XPHEnum::Value];
		// }else if($type==WebRole::UnitSupervisor[XPHEnum::Value]){
		// 	$type=AttendType::Unit[XPHEnum::Value];
		// // }

		// if($formdata['role']==AttendType::School[XPHEnum::Caption]){
		// 	$type=AttendType::School[XPHEnum::Value];
		// }else if($formdata['role']==AttendType::Unit[XPHEnum::Caption]){
		// 	$type=AttendType::Unit[XPHEnum::Value];
		// }else if($formdata['role']==AttendType::Outside[XPHEnum::Caption]){
		// 	$type=AttendType::Outside[XPHEnum::Value];
		// }
		$type = $formdata['role'];
		// $serial_no=$formdata['attend1'];
		$academic_year = $formdata['attend2'];
		$semester = $formdata['attend3'];
		// $class_name=$data['name'];
		// $class_type=$data['type'];
		// $teacher_name=$data1['username'];
		// $title=$data1['title'];
		// $dept_name=$data1['dept_name'];
		// $age_groups=$data1['age_groups'];
		// $teachers_attribute=$data1['teachers_attribute'];
		// $listen_name=$data2['username'];
		// $listen_address=$data['classroom'];
		// $course_units=$data['course_units'];
		$listen_class = $formdata['attend4'];
		if (isset($formdata['attend5'])) {
			$advice = $formdata['attend5'];
		} else {
			$advice = '';
		}


		$class_name = $formdata['class_name'];
		$class_type = $formdata['class_type'];
		$teacher_name = $formdata['teacher_name'];
		$teacher_code = $formdata['teacher_code'];
		$title = $formdata['teacher_title'];
		$dept_name = $formdata['dept_name'];
		$age_groups = $formdata['age_groups'];
		$teachers_attribute = $formdata['teachers_attribute'];
		$listen_name = $data2['username'];
		$listen_address = $formdata['listen_address'];
		$course_units = $formdata['course_units'];
		$class_id = $formdata['class_id'];

		$listen_type = $formdata['listen_type'];

		// $age_groups=(new AgeGroups)->show($age_groups);
		// $teachers_attribute=(new TeachersAttribute)->show($teachers_attribute);
		//教学水平
		if ($formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {
			$teachingLevel[0] = isset($formdata['teachingLevel'][0]) ? $formdata['teachingLevel'][0] : exit(retJson("请选择完整的教学能力分数", false));
			$teachingLevel[1] = isset($formdata['teachingLevel'][1]) ? $formdata['teachingLevel'][1] : exit(retJson("请选择完整的教学能力分数", false));
			$teachingLevel[2] = isset($formdata['teachingLevel'][2]) ? $formdata['teachingLevel'][2] : exit(retJson("请选择完整的教学能力分数", false));
			$teachingLevel[3] = isset($formdata['teachingLevel'][3]) ? $formdata['teachingLevel'][3] : exit(retJson("请选择完整的教学能力分数", false));
			if ($_POST['cc_type'] == 2 || $_POST['cc_type'] == 4) { //实训课或者体育课有第4个
				$teachingLevel[4] = isset($formdata['teachingLevel'][4]) ? $formdata['teachingLevel'][4] : exit(retJson("请选择完整的教学能力分数", false));
			}
		}else{
			$teachingLevel[0] = isset($formdata['teachingLevel'][0]) ? $formdata['teachingLevel'][0] : '';
			$teachingLevel[1] = isset($formdata['teachingLevel'][1]) ? $formdata['teachingLevel'][1] : '';
			$teachingLevel[2] = isset($formdata['teachingLevel'][2]) ? $formdata['teachingLevel'][2] : '';
			$teachingLevel[3] = isset($formdata['teachingLevel'][3]) ? $formdata['teachingLevel'][3] :'';
			if ($_POST['cc_type'] == 2 || $_POST['cc_type'] == 4) { //实训课或者体育课
				$teachingLevel[4] = isset($formdata['teachingLevel'][4]) ? $formdata['teachingLevel'][4] : '';
			}
		}
		
		$teachingLevel_rank = array('0', '0', '0', '0', '0');
		$teachingLevel_count = 0;
		if($teachingLevel){
			foreach ($teachingLevel as $k => $v) {
				$teachingLevel_count = $teachingLevel_count + $teachingLevel[$k];
			}
			if ($teachingLevel_count >= 90) {
				$teachingLevel_rank[0] = '1';
			} else if ($teachingLevel_count >= 80 and $teachingLevel_count < 90) {
				$teachingLevel_rank[1] = '1';
			} else if ($teachingLevel_count >= 70 and $teachingLevel_count < 80) {
				$teachingLevel_rank[2] = '1';
			} else if ($teachingLevel_count >= 60 and $teachingLevel_count < 70) {
				$teachingLevel_rank[3] = '1';
			} else if ($teachingLevel_count < 60) {
				$teachingLevel_rank[4] = '1';
			}
		}
		

		//教学效果
		if ($formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {
			$teachingEffect = isset($formdata['teachingEffect']) ? $formdata['teachingEffect'] : exit(retJson("请选择完整的学生状况分数", false));
		}else{
			$teachingEffect = isset($formdata['teachingEffect']) ? $formdata['teachingEffect'] : array();
		}

		$teachingEffect_rank = array('0', '0', '0', '0', '0');
		$teachingEffect_count = 0;
		if($teachingEffect){
			foreach ($teachingEffect as $k => $v) {
				$teachingEffect_count = $teachingEffect_count + $teachingEffect[$k];
			}
			if ($teachingEffect_count >= 90) {
				$teachingEffect_rank[0] = '1';
			} else if ($teachingEffect_count >= 80 and $teachingEffect_count < 90) {
				$teachingEffect_rank[1] = '1';
			} else if ($teachingEffect_count >= 70 and $teachingEffect_count < 80) {
				$teachingEffect_rank[2] = '1';
			} else if ($teachingEffect_count >= 60 and $teachingEffect_count < 70) {
				$teachingEffect_rank[3] = '1';
			} else if ($teachingEffect_count < 60) {
				$teachingEffect_rank[4] = '1';
			}
		}
		
		//听课记录附件
		if (isset($formdata['attend_img1']) && $formdata['attend_img1'][UploadType::AttendImg[XPHEnum::Value]]) {
			$attend_img1 =  $formdata['attend_img1'][UploadType::AttendImg[XPHEnum::Value]];
			$attend_img1_value = array();
			foreach ($attend_img1 as $ks => $vs) {
				$attend_img1_value[$ks]['img'] = $vs;
			}
		} else {
			$attend_img1_value = array();
		}

		//意见或建议附件
		if (isset($formdata['attend_img2']) && $formdata['attend_img2'][UploadType::AttendImg[XPHEnum::Value]]) {
			$attend_img2 =  $formdata['attend_img2'][UploadType::AttendImg[XPHEnum::Value]];
			$attend_img2_value = array();
			foreach ($attend_img2 as $ks => $vs) {
				$attend_img2_value[$ks]['img'] = $vs;
			}
		} else {
			$attend_img2_value = array();
		}

		//学生常态附件
		if (isset($formdata['attend_img3']) && $formdata['attend_img3'][UploadType::AttendImg[XPHEnum::Value]]) {
			$attend_img3 =  $formdata['attend_img3'][UploadType::AttendImg[XPHEnum::Value]];
			$attend_img3_value = array();
			foreach ($attend_img3 as $ks => $vs) {
				$attend_img3_value[$ks]['img'] = $vs;
			}
		} else {
			$attend_img3_value = array();
		}

		if (isset($formdata['attend_record_content'])) {
			$commentary = $formdata['attend_record_content'];
		} else {
			$commentary = '';
		}
	

		$is_add = $formdata['is_add'];
		if ($formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {
			$status = AttendStatus::Submit[XPHEnum::Value];
		} else {
			$status = AttendStatus::Save[XPHEnum::Value];
		}

		if ($_POST['cc_type'] == 2) { //实训课的时候
			$param = array(
				'attend' => array(
					'class_id' => $class_id,
					'listen_id' => getSess()['id'],
					'type' => $type,
					// 'serial_no'=>$serial_no,
					'academic_year' => $academic_year, //学年
					'semester' => $semester, //学期
					'class_name' => $class_name,
					'class_type' => $class_type,
					'cc_type' => $_POST['cc_type'],
					'teacher_name' => $teacher_name,
					'teacher_code' => $teacher_code,
					'title' => $title,
					'dept_name' => $dept_name,
					'age_groups' => $age_groups,
					'teachers_attribute' => $teachers_attribute,
					'listen_name' => $listen_name,
					'listen_time' => $formdata['listen_time'],
					'listen_address' => $listen_address,
					'course_units' => $course_units,
					'listen_class' => $listen_class,
					// 'classroom_facilities'=>$classroom_facilities_item,
					// 'classroom_environmental'=>$classroom_environmental_item,
					'advice' => $advice,
					'teaching_level_score' => $teachingLevel_count,
					'teaching_effect_score' => $teachingEffect_count,
					'status' => $status,
					// 0415新增总分 教学70%+学生30%
					'score' => ($teachingLevel_count + $teachingEffect_count),
					'listen_type' => $listen_type
				),
				'attends_teaching_content' => array(
					0 => array('key_index' => $formdata['attends_teaching_index'][0], 'list_id' => $formdata['attends_teaching_list_id'][0], 'content' => $formdata['attends_teaching_content'][0], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[0]),
					1 => array('key_index' => $formdata['attends_teaching_index'][1], 'list_id' => $formdata['attends_teaching_list_id'][1], 'content' => $formdata['attends_teaching_content'][1], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[1]),
					2 => array('key_index' => $formdata['attends_teaching_index'][2], 'list_id' => $formdata['attends_teaching_list_id'][2], 'content' => $formdata['attends_teaching_content'][2], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[2]),
					3 => array('key_index' => $formdata['attends_teaching_index'][3], 'list_id' => $formdata['attends_teaching_list_id'][3], 'content' => $formdata['attends_teaching_content'][3], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[3]),
					4 => array('key_index' => $formdata['attends_teaching_index'][4], 'list_id' => $formdata['attends_teaching_list_id'][4], 'content' => $formdata['attends_teaching_content'][4], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[4])
					// ,
					// 2=>array('key_index'=>$formdata['attend_teaching_index'][2],'list_id'=>$formdata['attend_teaching_list_id'][2],'content'=>$formdata['attend_teaching_content'][2],'score'=>$formdata['attend_teaching_score'][0],'get_score'=>$teachingLevel[2])
				),
				'attend_teaching_level' => array(
					0 => array('item' => $formdata['attend_teaching_level_item'][0], 'remark' => $formdata['attend_teaching_level_remark'][0], 'is_check' => $teachingLevel_rank[0]),
					1 => array('item' => $formdata['attend_teaching_level_item'][1], 'remark' => $formdata['attend_teaching_level_remark'][1], 'is_check' => $teachingLevel_rank[1]),
					2 => array('item' => $formdata['attend_teaching_level_item'][2], 'remark' => $formdata['attend_teaching_level_remark'][2], 'is_check' => $teachingLevel_rank[2]),
					3 => array('item' => $formdata['attend_teaching_level_item'][3], 'remark' => $formdata['attend_teaching_level_remark'][3], 'is_check' => $teachingLevel_rank[3]),
					4 => array('item' => $formdata['attend_teaching_level_item'][4], 'remark' => $formdata['attend_teaching_level_remark'][4], 'is_check' => $teachingLevel_rank[4])
				),
				'attend_student_status' => array(
					0 => array('key_index' => $formdata['attend_student_status_index'][0], 'list_id' => $formdata['attend_student_status_list_id'][0], 'content' => $formdata['attend_student_status'][0], 'score' => $formdata['attend_student_status_score'][0], 'get_score' => isset($teachingEffect[0])?$teachingEffect[0]:'')
					// ,
					// 1=>array('key_index'=>$formdata['attend_student_status_index'][1],'list_id'=>$formdata['attend_student_status_list_id'][1],'content'=>$formdata['attend_student_status'][1],'score'=>$formdata['attend_student_status_score'][1],'get_score'=>$teachingEffect[1]),
					// 2=>array('key_index'=>$formdata['attend_student_status_index'][2],'list_id'=>$formdata['attend_student_status_list_id'][2],'content'=>$formdata['attend_student_status'][2],'score'=>$formdata['attend_student_status_score'][2],'get_score'=>$teachingEffect[2]),
					// 3=>array('key_index'=>$formdata['attend_student_status_index'][3],'list_id'=>$formdata['attend_student_status_list_id'][3],'content'=>$formdata['attend_student_status'][3],'score'=>$formdata['attend_student_status_score'][3],'get_score'=>$teachingEffect[3]),
					// 4=>array('key_index'=>$formdata['attend_student_status_index'][4],'list_id'=>$formdata['attend_student_status_list_id'][4],'content'=>$formdata['attend_student_status'][4],'score'=>$formdata['attend_student_status_score'][4],'get_score'=>$teachingEffect[4]),
					// 5=>array('key_index'=>$formdata['attend_student_status_index'][5],'list_id'=>$formdata['attend_student_status_list_id'][5],'content'=>$formdata['attend_student_status'][5],'score'=>$formdata['attend_student_status_score'][5],'get_score'=>$teachingEffect[5])
				),
				'attend_teaching_effect' => array(
					0 => array('item' => $formdata['attend_student_status_item'][0], 'remark' => $formdata['attend_student_status_remark'][0], 'is_check' => $teachingEffect_rank[0])
					// ,
					// 1=>array('item'=>$formdata['attend_student_status_item'][1],'remark'=>$formdata['attend_student_status_remark'][1],'is_check'=>$teachingEffect_rank[1]),
					// 2=>array('item'=>$formdata['attend_student_status_item'][2],'remark'=>$formdata['attend_student_status_remark'][2],'is_check'=>$teachingEffect_rank[2]),
					// 3=>array('item'=>$formdata['attend_student_status_item'][3],'remark'=>$formdata['attend_student_status_remark'][3],'is_check'=>$teachingEffect_rank[3]),
					// 4=>array('item'=>$formdata['attend_student_status_item'][4],'remark'=>$formdata['attend_student_status_remark'][4],'is_check'=>$teachingEffect_rank[4])
				),
				/* 'attend_teaching_readiness'=>array(
					0=>array('item'=>$formdata['attend_teaching_readiness_content'][0],'option'=>$formdata['attend_teaching_readiness_option'][0],'check_value'=>$teachingReadiness[0]),
					1=>array('item'=>$formdata['attend_teaching_readiness_content'][1],'option'=>$formdata['attend_teaching_readiness_option'][1],'check_value'=>$teachingReadiness[1]),
					2=>array('item'=>$formdata['attend_teaching_readiness_content'][2],'option'=>$formdata['attend_teaching_readiness_option'][2],'check_value'=>$teachingReadiness[2]),
					3=>array('item'=>$formdata['attend_teaching_readiness_content'][3],'option'=>$formdata['attend_teaching_readiness_option'][3],'check_value'=>$teachingReadiness[3]),
					4=>array('item'=>$formdata['attend_teaching_readiness_content'][4],'option'=>$formdata['attend_teaching_readiness_option'][4],'check_value'=>$teachingReadiness[4]),
					5=>array('item'=>$formdata['attend_teaching_readiness_content'][5],'option'=>$formdata['attend_teaching_readiness_option'][5],'check_value'=>$teachingReadiness[5]),
					6=>array('item'=>$formdata['attend_teaching_readiness_content'][6],'option'=>$formdata['attend_teaching_readiness_option'][6],'check_value'=>$teachingReadiness[6]),
					7=>array('item'=>$formdata['attend_teaching_readiness_content'][7],'option'=>$formdata['attend_teaching_readiness_option'][7],'check_value'=>$teachingReadiness[7]),
					8=>array('item'=>$formdata['attend_teaching_readiness_content'][8],'option'=>$formdata['attend_teaching_readiness_option'][8],'check_value'=>$teachingReadiness[8]),
					9=>array('item'=>$formdata['attend_teaching_readiness_content'][9],'option'=>$formdata['attend_teaching_readiness_option'][9],'check_value'=>$teachingReadiness[9]),
					10=>array('item'=>$formdata['attend_teaching_readiness_content'][10],'option'=>$formdata['attend_teaching_readiness_option'][10],'check_value'=>$teachingReadiness[10]),
					11=>array('item'=>$formdata['attend_teaching_readiness_content'][11],'option'=>$formdata['attend_teaching_readiness_option'][11],'check_value'=>$teachingReadiness[11])
				),
				'attend_students_norm'=>array(
					0=>array('item'=>$formdata['attend_students_norm_item'][0],'check_value'=>$studentsNorm[0]),
					1=>array('item'=>$formdata['attend_students_norm_item'][1],'check_value'=>$studentsNorm[1]),
					2=>array('item'=>$formdata['attend_students_norm_item'][2],'check_value'=>$studentsNorm[2]),
					3=>array('item'=>$formdata['attend_students_norm_item'][3],'check_value'=>round($studentsNorm[3],2).'%'),
					4=>array('item'=>$formdata['attend_students_norm_item'][4],'check_value'=>$studentsNorm[4]),
					5=>array('item'=>$formdata['attend_students_norm_item'][5],'check_value'=>$studentsNorm[5]),
					6=>array('item'=>$formdata['attend_students_norm_item'][6],'check_value'=>$studentsNorm[6]),
					7=>array('item'=>$formdata['attend_students_norm_item'][7],'check_value'=>$studentsNorm[7]),
					8=>array('item'=>$formdata['attend_students_norm_item'][8],'check_value'=>$studentsNorm[8])				
				),
				'attend_classroom_facilities'=>array('option'=>$formdata['attend_classroom_facilities_option'],'check_value'=>$formdata['classroom_facilities']),
				'attend_classroom_environmental'=>array('option'=>$formdata['classroom_environmental_option'],'check_value'=>$formdata['classroom_environmental']), */
				'attend_record' => array(
					0 => array('time' => $formdata['attend_record_time'], 'activity' => null, 'commentary' => $commentary)
				),
				'attend_img1' => $attend_img1_value,
				'attend_img2' => $attend_img2_value,
				'attend_img3' => $attend_img3_value,
			);
		}else if($_POST['cc_type'] == 3){//思政课
			$param = array(
				'attend' => array(
					'class_id' => $class_id,
					'listen_id' => getSess()['id'],
					'type' => $type,
					// 'serial_no'=>$serial_no,
					'academic_year' => $academic_year, //学年
					'semester' => $semester, //学期
					'class_name' => $class_name,
					'class_type' => $class_type,
					'cc_type' => $_POST['cc_type'],
					'teacher_name' => $teacher_name,
					'teacher_code' => $teacher_code,
					'title' => $title,
					'dept_name' => $dept_name,
					'age_groups' => $age_groups,
					'teachers_attribute' => $teachers_attribute,
					'listen_name' => $listen_name,
					'listen_time' => $formdata['listen_time'],
					'listen_address' => $listen_address,
					'course_units' => $course_units,
					'listen_class' => $listen_class,
					// 'classroom_facilities'=>$classroom_facilities_item,
					// 'classroom_environmental'=>$classroom_environmental_item,
					'advice' => $advice,
					'teaching_level_score' => $teachingLevel_count,
					'teaching_effect_score' => $teachingEffect_count,
					'status' => $status,
					// 0415新增总分 教学70%+学生30%
					'score' => ($teachingLevel_count  + $teachingEffect_count ),
					'listen_type' => $listen_type
				),
				'attend3_teaching_content' => array(
					0 => array('key_index' => $formdata['attend3_teaching_index'][0], 'list_id' => $formdata['attend3_teaching_list_id'][0], 'content' => $formdata['attend3_teaching_content'][0], 'score' => $formdata['attend3_teaching_score'][0], 'get_score' => $teachingLevel[0]),
					1 => array('key_index' => $formdata['attend3_teaching_index'][1], 'list_id' => $formdata['attend3_teaching_list_id'][1], 'content' => $formdata['attend3_teaching_content'][1], 'score' => $formdata['attend3_teaching_score'][0], 'get_score' => $teachingLevel[1]),
					2 => array('key_index' => $formdata['attend3_teaching_index'][2], 'list_id' => $formdata['attend3_teaching_list_id'][2], 'content' => $formdata['attend3_teaching_content'][2], 'score' => $formdata['attend3_teaching_score'][0], 'get_score' => $teachingLevel[2]),
					3 => array('key_index' => $formdata['attend3_teaching_index'][3], 'list_id' => $formdata['attend3_teaching_list_id'][3], 'content' => $formdata['attend3_teaching_content'][3], 'score' => $formdata['attend3_teaching_score'][0], 'get_score' => $teachingLevel[3])
					// ,
					// 2=>array('key_index'=>$formdata['attend_teaching_index'][2],'list_id'=>$formdata['attend_teaching_list_id'][2],'content'=>$formdata['attend_teaching_content'][2],'score'=>$formdata['attend_teaching_score'][0],'get_score'=>$teachingLevel[2])
				),
				'attend_teaching_level' => array(
					0 => array('item' => $formdata['attend_teaching_level_item'][0], 'remark' => $formdata['attend_teaching_level_remark'][0], 'is_check' => $teachingLevel_rank[0]),
					1 => array('item' => $formdata['attend_teaching_level_item'][1], 'remark' => $formdata['attend_teaching_level_remark'][1], 'is_check' => $teachingLevel_rank[1]),
					2 => array('item' => $formdata['attend_teaching_level_item'][2], 'remark' => $formdata['attend_teaching_level_remark'][2], 'is_check' => $teachingLevel_rank[2]),
					3 => array('item' => $formdata['attend_teaching_level_item'][3], 'remark' => $formdata['attend_teaching_level_remark'][3], 'is_check' => $teachingLevel_rank[3]),
					// 4 => array('item' => $formdata['attend_teaching_level_item'][4], 'remark' => $formdata['attend_teaching_level_remark'][4], 'is_check' => $teachingLevel_rank[4])
				),
				'attend_student_status' => array(
					0 => array('key_index' => $formdata['attend_student_status_index'][0], 'list_id' => $formdata['attend_student_status_list_id'][0], 'content' => $formdata['attend_student_status'][0], 'score' => $formdata['attend_student_status_score'][0], 'get_score' => isset($teachingEffect[0])?$teachingEffect[0]:'')
					// ,
					// 1=>array('key_index'=>$formdata['attend_student_status_index'][1],'list_id'=>$formdata['attend_student_status_list_id'][1],'content'=>$formdata['attend_student_status'][1],'score'=>$formdata['attend_student_status_score'][1],'get_score'=>$teachingEffect[1]),
					// 2=>array('key_index'=>$formdata['attend_student_status_index'][2],'list_id'=>$formdata['attend_student_status_list_id'][2],'content'=>$formdata['attend_student_status'][2],'score'=>$formdata['attend_student_status_score'][2],'get_score'=>$teachingEffect[2]),
					// 3=>array('key_index'=>$formdata['attend_student_status_index'][3],'list_id'=>$formdata['attend_student_status_list_id'][3],'content'=>$formdata['attend_student_status'][3],'score'=>$formdata['attend_student_status_score'][3],'get_score'=>$teachingEffect[3]),
					// 4=>array('key_index'=>$formdata['attend_student_status_index'][4],'list_id'=>$formdata['attend_student_status_list_id'][4],'content'=>$formdata['attend_student_status'][4],'score'=>$formdata['attend_student_status_score'][4],'get_score'=>$teachingEffect[4]),
					// 5=>array('key_index'=>$formdata['attend_student_status_index'][5],'list_id'=>$formdata['attend_student_status_list_id'][5],'content'=>$formdata['attend_student_status'][5],'score'=>$formdata['attend_student_status_score'][5],'get_score'=>$teachingEffect[5])
				),
				'attend_teaching_effect' => array(
					0 => array('item' => $formdata['attend_student_status_item'][0], 'remark' => $formdata['attend_student_status_remark'][0], 'is_check' => $teachingEffect_rank[0])
					// ,
					// 1=>array('item'=>$formdata['attend_student_status_item'][1],'remark'=>$formdata['attend_student_status_remark'][1],'is_check'=>$teachingEffect_rank[1]),
					// 2=>array('item'=>$formdata['attend_student_status_item'][2],'remark'=>$formdata['attend_student_status_remark'][2],'is_check'=>$teachingEffect_rank[2]),
					// 3=>array('item'=>$formdata['attend_student_status_item'][3],'remark'=>$formdata['attend_student_status_remark'][3],'is_check'=>$teachingEffect_rank[3]),
					// 4=>array('item'=>$formdata['attend_student_status_item'][4],'remark'=>$formdata['attend_student_status_remark'][4],'is_check'=>$teachingEffect_rank[4])
				),
				/* 'attend_teaching_readiness'=>array(
					0=>array('item'=>$formdata['attend_teaching_readiness_content'][0],'option'=>$formdata['attend_teaching_readiness_option'][0],'check_value'=>$teachingReadiness[0]),
					1=>array('item'=>$formdata['attend_teaching_readiness_content'][1],'option'=>$formdata['attend_teaching_readiness_option'][1],'check_value'=>$teachingReadiness[1]),
					2=>array('item'=>$formdata['attend_teaching_readiness_content'][2],'option'=>$formdata['attend_teaching_readiness_option'][2],'check_value'=>$teachingReadiness[2]),
					3=>array('item'=>$formdata['attend_teaching_readiness_content'][3],'option'=>$formdata['attend_teaching_readiness_option'][3],'check_value'=>$teachingReadiness[3]),
					4=>array('item'=>$formdata['attend_teaching_readiness_content'][4],'option'=>$formdata['attend_teaching_readiness_option'][4],'check_value'=>$teachingReadiness[4]),
					5=>array('item'=>$formdata['attend_teaching_readiness_content'][5],'option'=>$formdata['attend_teaching_readiness_option'][5],'check_value'=>$teachingReadiness[5]),
					6=>array('item'=>$formdata['attend_teaching_readiness_content'][6],'option'=>$formdata['attend_teaching_readiness_option'][6],'check_value'=>$teachingReadiness[6]),
					7=>array('item'=>$formdata['attend_teaching_readiness_content'][7],'option'=>$formdata['attend_teaching_readiness_option'][7],'check_value'=>$teachingReadiness[7]),
					8=>array('item'=>$formdata['attend_teaching_readiness_content'][8],'option'=>$formdata['attend_teaching_readiness_option'][8],'check_value'=>$teachingReadiness[8]),
					9=>array('item'=>$formdata['attend_teaching_readiness_content'][9],'option'=>$formdata['attend_teaching_readiness_option'][9],'check_value'=>$teachingReadiness[9]),
					10=>array('item'=>$formdata['attend_teaching_readiness_content'][10],'option'=>$formdata['attend_teaching_readiness_option'][10],'check_value'=>$teachingReadiness[10]),
					11=>array('item'=>$formdata['attend_teaching_readiness_content'][11],'option'=>$formdata['attend_teaching_readiness_option'][11],'check_value'=>$teachingReadiness[11])
				),
				'attend_students_norm'=>array(
					0=>array('item'=>$formdata['attend_students_norm_item'][0],'check_value'=>$studentsNorm[0]),
					1=>array('item'=>$formdata['attend_students_norm_item'][1],'check_value'=>$studentsNorm[1]),
					2=>array('item'=>$formdata['attend_students_norm_item'][2],'check_value'=>$studentsNorm[2]),
					3=>array('item'=>$formdata['attend_students_norm_item'][3],'check_value'=>round($studentsNorm[3],2).'%'),
					4=>array('item'=>$formdata['attend_students_norm_item'][4],'check_value'=>$studentsNorm[4]),
					5=>array('item'=>$formdata['attend_students_norm_item'][5],'check_value'=>$studentsNorm[5]),
					6=>array('item'=>$formdata['attend_students_norm_item'][6],'check_value'=>$studentsNorm[6]),
					7=>array('item'=>$formdata['attend_students_norm_item'][7],'check_value'=>$studentsNorm[7]),
					8=>array('item'=>$formdata['attend_students_norm_item'][8],'check_value'=>$studentsNorm[8])				
				),
				'attend_classroom_facilities'=>array('option'=>$formdata['attend_classroom_facilities_option'],'check_value'=>$formdata['classroom_facilities']),
				'attend_classroom_environmental'=>array('option'=>$formdata['classroom_environmental_option'],'check_value'=>$formdata['classroom_environmental']), */
				'attend_record' => array(
					0 => array('time' => $formdata['attend_record_time'], 'activity' => null, 'commentary' => $commentary)
				),
				'attend_img1' => $attend_img1_value,
				'attend_img2' => $attend_img2_value,
				'attend_img3' => $attend_img3_value,
			);
		}else if ($_POST['cc_type'] ==4) {
			$param = array(
				'attend' => array(
					'class_id' => $class_id,
					'listen_id' =>getSess()['id'],
					'type' => $type,
					// 'serial_no'=>$serial_no,
					'academic_year' => $academic_year, //学年
					'semester' => $semester, //学期
					'class_name' => $class_name,
					'class_type' => $class_type,
					'cc_type' => $_POST['cc_type'],
					'teacher_name' => $teacher_name,
					'teacher_code' => $teacher_code,
					'title' => $title,
					'dept_name' => $dept_name,
					'age_groups' => $age_groups,
					'teachers_attribute' => $teachers_attribute,
					'listen_name' => $listen_name,
					'listen_time' => $formdata['listen_time'],
					'listen_address' => $listen_address,
					'course_units' => $course_units,
					'listen_class' => $listen_class,
					// 'classroom_facilities'=>$classroom_facilities_item,
					// 'classroom_environmental'=>$classroom_environmental_item,
					'advice' => $advice,
					'teaching_level_score' => $teachingLevel_count,
					'teaching_effect_score' => $teachingEffect_count,
					'status' => $status,
					// 0415新增总分 教学70%+学生30%
					'score' => ($teachingLevel_count  + $teachingEffect_count ),
					// 0723新增听课类型
					'listen_type' => $listen_type
				),
				'attend4_teaching_content' => array(
					0 => array('key_index' => $formdata['attend4_teaching_index'][0], 'list_id' => $formdata['attend4_teaching_list_id'][0], 'content' => $formdata['attend4_teaching_content'][0], 'score' => $formdata['attend4_teaching_score'][0], 'get_score' => $teachingLevel[0]),
					1 => array('key_index' => $formdata['attend4_teaching_index'][1], 'list_id' => $formdata['attend4_teaching_list_id'][1], 'content' => $formdata['attend4_teaching_content'][1], 'score' => $formdata['attend4_teaching_score'][0], 'get_score' => $teachingLevel[1]),
					2 => array('key_index' => $formdata['attend4_teaching_index'][2], 'list_id' => $formdata['attend4_teaching_list_id'][2], 'content' => $formdata['attend4_teaching_content'][2], 'score' => $formdata['attend4_teaching_score'][0], 'get_score' => $teachingLevel[2]),
					3 => array('key_index' => $formdata['attend4_teaching_index'][3], 'list_id' => $formdata['attend4_teaching_list_id'][3], 'content' => $formdata['attend4_teaching_content'][3], 'score' => $formdata['attend4_teaching_score'][0], 'get_score' => $teachingLevel[3]),
					4 => array('key_index' => $formdata['attend4_teaching_index'][4], 'list_id' => $formdata['attend4_teaching_list_id'][4], 'content' => $formdata['attend4_teaching_content'][4], 'score' => $formdata['attend4_teaching_score'][0], 'get_score' => $teachingLevel[4])
					// ,
					// 2=>array('key_index'=>$formdata['attend_teaching_index'][2],'list_id'=>$formdata['attend_teaching_list_id'][2],'content'=>$formdata['attend_teaching_content'][2],'score'=>$formdata['attend_teaching_score'][0],'get_score'=>$teachingLevel[2])
				),
				'attend_teaching_level' => array(
					0 => array('item' => $formdata['attend_teaching_level_item'][0], 'remark' => $formdata['attend_teaching_level_remark'][0], 'is_check' => $teachingLevel_rank[0]),
					1 => array('item' => $formdata['attend_teaching_level_item'][1], 'remark' => $formdata['attend_teaching_level_remark'][1], 'is_check' => $teachingLevel_rank[1]),
					2 => array('item' => $formdata['attend_teaching_level_item'][2], 'remark' => $formdata['attend_teaching_level_remark'][2], 'is_check' => $teachingLevel_rank[2]),
					3 => array('item' => $formdata['attend_teaching_level_item'][3], 'remark' => $formdata['attend_teaching_level_remark'][3], 'is_check' => $teachingLevel_rank[3]),
				//	4 => array('item' => $formdata['attend_teaching_level_item'][4], 'remark' => $formdata['attend_teaching_level_remark'][4], 'is_check' => $teachingLevel_rank[4])
				),
				'attend_student_status' => array(
					0 => array('key_index' => $formdata['attend_student_status_index'][0], 'list_id' => $formdata['attend_student_status_list_id'][0], 'content' => $formdata['attend_student_status'][0], 'score' => $formdata['attend_student_status_score'][0], 'get_score' => $teachingEffect[0])
				),
				'attend_teaching_effect' => array(
					0 => array('item' => $formdata['attend_student_status_item'][0], 'remark' => $formdata['attend_student_status_remark'][0], 'is_check' => $teachingEffect_rank[0])
				),
				'attend_record' => array(
					0 => array('time' => $formdata['attend_record_time'], 'activity' => null, 'commentary' => $formdata['attend_record_content'])
				),
				'attend_img1' => $attend_img1_value,
				'attend_img2' => $attend_img2_value,
				'attend_img3' => $attend_img3_value,
			);
		}
		 else {
			$param = array(
				'attend' => array(
					'class_id' => $class_id,
					'listen_id' => getSess()['id'],
					'type' => $type,
					// 'serial_no'=>$serial_no,
					'academic_year' => $academic_year, //学年
					'semester' => $semester, //学期
					'class_name' => $class_name,
					'class_type' => $class_type,
					'cc_type' => $_POST['cc_type'],
					'teacher_name' => $teacher_name,
					'teacher_code' => $teacher_code,
					'title' => $title,
					'dept_name' => $dept_name,
					'age_groups' => $age_groups,
					'teachers_attribute' => $teachers_attribute,
					'listen_name' => $listen_name,
					'listen_time' => $formdata['listen_time'],
					'listen_address' => $listen_address,
					'course_units' => $course_units,
					'listen_class' => $listen_class,
					// 'classroom_facilities'=>$classroom_facilities_item,
					// 'classroom_environmental'=>$classroom_environmental_item,
					'advice' => $advice,
					'teaching_level_score' => $teachingLevel_count,
					'teaching_effect_score' => $teachingEffect_count,
					'status' => $status,
					// 0415新增总分 教学70%+学生30%
					'score' => ($teachingLevel_count + $teachingEffect_count ),
					'listen_type' => $listen_type
				),
				'attend_teaching_content' => array(
					0 => array('key_index' => $formdata['attend_teaching_index'][0], 'list_id' => $formdata['attend_teaching_list_id'][0], 'content' => $formdata['attend_teaching_content'][0], 'score' => $formdata['attend_teaching_score'][0], 'get_score' => $teachingLevel[0]),
					1 => array('key_index' => $formdata['attend_teaching_index'][1], 'list_id' => $formdata['attend_teaching_list_id'][1], 'content' => $formdata['attend_teaching_content'][1], 'score' => $formdata['attend_teaching_score'][0], 'get_score' => $teachingLevel[1])
					// ,
					// 2=>array('key_index'=>$formdata['attend_teaching_index'][2],'list_id'=>$formdata['attend_teaching_list_id'][2],'content'=>$formdata['attend_teaching_content'][2],'score'=>$formdata['attend_teaching_score'][0],'get_score'=>$teachingLevel[2])
				),
				'attend_teaching_implementation' => array(
					0 => array('key_index' => $formdata['attend_teaching_implementation_index'][0], 'list_id' => $formdata['attend_teaching_implementation_list_id'][0], 'content' => $formdata['attend_teaching_implementation_content'][0], 'score' => $formdata['attend_teaching_implementation_score'][0], 'get_score' => $teachingLevel[2]),
					1 => array('key_index' => $formdata['attend_teaching_implementation_index'][1], 'list_id' => $formdata['attend_teaching_implementation_list_id'][1], 'content' => $formdata['attend_teaching_implementation_content'][1], 'score' => $formdata['attend_teaching_implementation_score'][1], 'get_score' => $teachingLevel[3])
					// ,
					// 2=>array('key_index'=>$formdata['attend_teaching_implementation_index'][2],'list_id'=>$formdata['attend_teaching_implementation_list_id'][2],'content'=>$formdata['attend_teaching_implementation_content'][2],'score'=>$formdata['attend_teaching_implementation_score'][2],'get_score'=>$teachingLevel[5]),
					// 3=>array('key_index'=>$formdata['attend_teaching_implementation_index'][3],'list_id'=>$formdata['attend_teaching_implementation_list_id'][3],'content'=>$formdata['attend_teaching_implementation_content'][3],'score'=>$formdata['attend_teaching_implementation_score'][3],'get_score'=>$teachingLevel[6]),
					// 4=>array('key_index'=>$formdata['attend_teaching_implementation_index'][4],'list_id'=>$formdata['attend_teaching_implementation_list_id'][4],'content'=>$formdata['attend_teaching_implementation_content'][4],'score'=>$formdata['attend_teaching_implementation_score'][4],'get_score'=>$teachingLevel[7]),
					// 5=>array('key_index'=>$formdata['attend_teaching_implementation_index'][5],'list_id'=>$formdata['attend_teaching_implementation_list_id'][5],'content'=>$formdata['attend_teaching_implementation_content'][5],'score'=>$formdata['attend_teaching_implementation_score'][5],'get_score'=>$teachingLevel[8])	
				),
				'attend_teaching_level' => array(
					0 => array('item' => $formdata['attend_teaching_level_item'][0], 'remark' => $formdata['attend_teaching_level_remark'][0], 'is_check' => $teachingLevel_rank[0]),
					1 => array('item' => $formdata['attend_teaching_level_item'][1], 'remark' => $formdata['attend_teaching_level_remark'][1], 'is_check' => $teachingLevel_rank[1]),
					2 => array('item' => $formdata['attend_teaching_level_item'][2], 'remark' => $formdata['attend_teaching_level_remark'][2], 'is_check' => $teachingLevel_rank[2]),
					3 => array('item' => $formdata['attend_teaching_level_item'][3], 'remark' => $formdata['attend_teaching_level_remark'][3], 'is_check' => $teachingLevel_rank[3]),
					4 => array('item' => $formdata['attend_teaching_level_item'][4], 'remark' => $formdata['attend_teaching_level_remark'][4], 'is_check' => $teachingLevel_rank[4])
				),
				'attend_student_status' => array(
					0 => array('key_index' => $formdata['attend_student_status_index'][0], 'list_id' => $formdata['attend_student_status_list_id'][0], 'content' => $formdata['attend_student_status'][0], 'score' => $formdata['attend_student_status_score'][0], 'get_score' => isset($teachingEffect[0])?$teachingEffect[0]:'')
					// ,
					// 1=>array('key_index'=>$formdata['attend_student_status_index'][1],'list_id'=>$formdata['attend_student_status_list_id'][1],'content'=>$formdata['attend_student_status'][1],'score'=>$formdata['attend_student_status_score'][1],'get_score'=>$teachingEffect[1]),
					// 2=>array('key_index'=>$formdata['attend_student_status_index'][2],'list_id'=>$formdata['attend_student_status_list_id'][2],'content'=>$formdata['attend_student_status'][2],'score'=>$formdata['attend_student_status_score'][2],'get_score'=>$teachingEffect[2]),
					// 3=>array('key_index'=>$formdata['attend_student_status_index'][3],'list_id'=>$formdata['attend_student_status_list_id'][3],'content'=>$formdata['attend_student_status'][3],'score'=>$formdata['attend_student_status_score'][3],'get_score'=>$teachingEffect[3]),
					// 4=>array('key_index'=>$formdata['attend_student_status_index'][4],'list_id'=>$formdata['attend_student_status_list_id'][4],'content'=>$formdata['attend_student_status'][4],'score'=>$formdata['attend_student_status_score'][4],'get_score'=>$teachingEffect[4]),
					// 5=>array('key_index'=>$formdata['attend_student_status_index'][5],'list_id'=>$formdata['attend_student_status_list_id'][5],'content'=>$formdata['attend_student_status'][5],'score'=>$formdata['attend_student_status_score'][5],'get_score'=>$teachingEffect[5])
				),
				'attend_teaching_effect' => array(
					0 => array('item' => $formdata['attend_student_status_item'][0], 'remark' => $formdata['attend_student_status_remark'][0], 'is_check' => $teachingEffect_rank[0])
					// ,
					// 1=>array('item'=>$formdata['attend_student_status_item'][1],'remark'=>$formdata['attend_student_status_remark'][1],'is_check'=>$teachingEffect_rank[1]),
					// 2=>array('item'=>$formdata['attend_student_status_item'][2],'remark'=>$formdata['attend_student_status_remark'][2],'is_check'=>$teachingEffect_rank[2]),
					// 3=>array('item'=>$formdata['attend_student_status_item'][3],'remark'=>$formdata['attend_student_status_remark'][3],'is_check'=>$teachingEffect_rank[3]),
					// 4=>array('item'=>$formdata['attend_student_status_item'][4],'remark'=>$formdata['attend_student_status_remark'][4],'is_check'=>$teachingEffect_rank[4])
				),
				/* 'attend_teaching_readiness'=>array(
					0=>array('item'=>$formdata['attend_teaching_readiness_content'][0],'option'=>$formdata['attend_teaching_readiness_option'][0],'check_value'=>$teachingReadiness[0]),
					1=>array('item'=>$formdata['attend_teaching_readiness_content'][1],'option'=>$formdata['attend_teaching_readiness_option'][1],'check_value'=>$teachingReadiness[1]),
					2=>array('item'=>$formdata['attend_teaching_readiness_content'][2],'option'=>$formdata['attend_teaching_readiness_option'][2],'check_value'=>$teachingReadiness[2]),
					3=>array('item'=>$formdata['attend_teaching_readiness_content'][3],'option'=>$formdata['attend_teaching_readiness_option'][3],'check_value'=>$teachingReadiness[3]),
					4=>array('item'=>$formdata['attend_teaching_readiness_content'][4],'option'=>$formdata['attend_teaching_readiness_option'][4],'check_value'=>$teachingReadiness[4]),
					5=>array('item'=>$formdata['attend_teaching_readiness_content'][5],'option'=>$formdata['attend_teaching_readiness_option'][5],'check_value'=>$teachingReadiness[5]),
					6=>array('item'=>$formdata['attend_teaching_readiness_content'][6],'option'=>$formdata['attend_teaching_readiness_option'][6],'check_value'=>$teachingReadiness[6]),
					7=>array('item'=>$formdata['attend_teaching_readiness_content'][7],'option'=>$formdata['attend_teaching_readiness_option'][7],'check_value'=>$teachingReadiness[7]),
					8=>array('item'=>$formdata['attend_teaching_readiness_content'][8],'option'=>$formdata['attend_teaching_readiness_option'][8],'check_value'=>$teachingReadiness[8]),
					9=>array('item'=>$formdata['attend_teaching_readiness_content'][9],'option'=>$formdata['attend_teaching_readiness_option'][9],'check_value'=>$teachingReadiness[9]),
					10=>array('item'=>$formdata['attend_teaching_readiness_content'][10],'option'=>$formdata['attend_teaching_readiness_option'][10],'check_value'=>$teachingReadiness[10]),
					11=>array('item'=>$formdata['attend_teaching_readiness_content'][11],'option'=>$formdata['attend_teaching_readiness_option'][11],'check_value'=>$teachingReadiness[11])
				),
				'attend_students_norm'=>array(
					0=>array('item'=>$formdata['attend_students_norm_item'][0],'check_value'=>$studentsNorm[0]),
					1=>array('item'=>$formdata['attend_students_norm_item'][1],'check_value'=>$studentsNorm[1]),
					2=>array('item'=>$formdata['attend_students_norm_item'][2],'check_value'=>$studentsNorm[2]),
					3=>array('item'=>$formdata['attend_students_norm_item'][3],'check_value'=>round($studentsNorm[3],2).'%'),
					4=>array('item'=>$formdata['attend_students_norm_item'][4],'check_value'=>$studentsNorm[4]),
					5=>array('item'=>$formdata['attend_students_norm_item'][5],'check_value'=>$studentsNorm[5]),
					6=>array('item'=>$formdata['attend_students_norm_item'][6],'check_value'=>$studentsNorm[6]),
					7=>array('item'=>$formdata['attend_students_norm_item'][7],'check_value'=>$studentsNorm[7]),
					8=>array('item'=>$formdata['attend_students_norm_item'][8],'check_value'=>$studentsNorm[8])				
				),
				'attend_classroom_facilities'=>array('option'=>$formdata['attend_classroom_facilities_option'],'check_value'=>$formdata['classroom_facilities']),
				'attend_classroom_environmental'=>array('option'=>$formdata['classroom_environmental_option'],'check_value'=>$formdata['classroom_environmental']), */
				'attend_record' => array(
					0 => array('time' => $formdata['attend_record_time'], 'activity' => null, 'commentary' => $commentary)
				),
				'attend_img1' => $attend_img1_value,
				'attend_img2' => $attend_img2_value,
				'attend_img3' => $attend_img3_value,
			);
		}



		if ($is_add == 0) {
			// pri($param);
			// exit;
			$result = $this->attend_service->saveAttend($param);
		} else {
			// pri($param);
			// exit;
			$result = $this->attend_service->saveAttend($param, $is_add); //1.id,2,
		}
		unset($_SESSION[SESS_ASSESS]);
		if ($formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {
			$this->Attend_model->update(array('id' => $attend_id, 'back_time' => null)); //清空回退时间
			exit(retJson('提交成功！', true, $result));
		} else {
			exit(retJson('保存成功！', true, $result));
		}
	}

	//督导批量提交听课
	function moreSubmit()
	{

		if (!isset($_POST['id'])) {
			exit(retJson('参数错误', false));
		}


		$ids =  implode(',', $_POST['id']);

		//听课 
		$connar['where'] = "id in(" . $ids . ")";
		$connar['orderby'] = 'FIELD(id,'.$ids.')';
		$attendArr = $this->Attend_model->get_list_full($connar);
		// echo $this->db->last_query();exit;
		$Error = '';$attend_id_arr = array();
		foreach ($attendArr as $key => $value) {
			if ($value['status'] == AttendStatus::Save[XPHEnum::Value]) {
				if ($value['course_units'] == '' || $value['listen_time'] == '' || $value['listen_time'] == '0'  || $value['class_name'] == '' || $value['teacher_name'] == '' || $value['dept_name'] == '' || $value['title'] == '' || $value['teachers_attribute'] == '' || $value['class_type'] == '' || $value['listen_class'] == '' || $value['listen_address'] == '' || $value['type'] == '' || $value['listen_type'] == '' || $value['teaching_level_score'] == '0' || $value['teaching_effect_score'] == '0' || $value['score'] == '0') {
					$Error .= '第'.($key+1).'行('.$value['listen_name'].'--'.$value['teacher_name'].')未填写完整的数据无法提交;<br/>';
					continue;
				}else{
					if ($value['type'] == AttendType::Teacher[XPHEnum::Value]) {
						$Error .= '第'.($key+1).'行教师听课类型无法提交;<br/>';
						continue;
					}else{
						$attend_id_arr[] = $value['id'];
					}
				}	

			}else{
				$Error .= '第'.($key+1).'行('.$value['listen_name'].'--'.$value['teacher_name'].')已提交无需再提交;<br/>';
				continue;
			}
		}
		if($Error != ''){
			exit(retJson($Error, false));
		}else{
			
			foreach($attend_id_arr as $k=>$v){
				$data['id'] = $v;
				$data['status'] =  AttendStatus::Submit[XPHEnum::Value];
				$data['back_time'] =  null;
				$this->Attend_model->update($data, 'id');
			}
			exit(retJson("提交成功.", true));
		}
			// if($value['status'] == AttendStatus::Submit[XPHEnum::Value]){
			//     exit(retJson('听课教师:'.$value['listen_name'].'---授课教师:'.$value['teacher_name'].'已提交无法修改',false));
			// }else{
			//     $data['id'] = $value['id'];
			//     $data['status'] =  AttendStatus::Submit[XPHEnum::Value];
			//     $data['back_time'] =  null;
			//     $this -> Attend_model ->update($data,'id');
			// }
			// if ($value['course_units'] == '' || $value['listen_time'] == '' || $value['class_name'] == '' || $value['teacher_name'] == '' || $value['dept_name'] == '' || $value['title'] == '' || $value['teachers_attribute'] == '' || $value['class_type'] == '' || $value['listen_class'] == '' || $value['listen_address'] == '' || $value['type'] == '' || $value['listen_type'] == '' || $value['teaching_level_score'] == '0' || $value['teaching_effect_score'] == '0' || $value['score'] == '0') {
			// 	// $attend_id .= ','.$value['id'];
			// 	// var_dump($value['id']);
			// 	$Error .= '部分未填写完整的数据无法提交';
			// 	continue;
			// 	// exit(retJson('未填写完整的数据无法提交', false));
			// } else {
			// 	//教师听课无法提交
			// 	if ($value['type'] == AttendType::Teacher[XPHEnum::Value]) {
			// 		$Error .= '部分教师听课无法提交';
			// 		continue;
			// 		// exit(retJson('教师听课无法提交', false));
			// 	} else {
			// 		// 批量提交未提交的听课记录
			// 		// if ($value['status'] == AttendStatus::Save[XPHEnum::Value]) {
			// 		// 	$data['id'] = $value['id'];
			// 		// 	$data['status'] =  AttendStatus::Submit[XPHEnum::Value];
			// 		// 	$data['back_time'] =  null;
			// 		// 	$this->Attend_model->update($data, 'id');
			// 		// } 
			// 		// else {
			// 		// 	exit(retJson('已提交的无需再提交', false));
			// 		// }
			// 	}
			// }
		

		var_dump($Error);

		// exit(retJson("已提交成功.".$Error, true));
	}


	//已提交督导听课
	function SubmittedAssess()
	{
		$connar['where'] = $this->sqlEscape("listen_id=?? and status<>??", array($_SESSION[SESS_USER_HOME]['id'], AttendStatus::Deleted[XPHEnum::Value]));
		$connar['orderby'] = 'created desc';
		$result['detail'] = $this->Attend_model->get_list_full($connar);
		foreach ($result['detail'] as $k => $v) {
			$result['detail'][$k]['type_char'] = (new AttendType)->show($v['type']);
		}
		// var_dump($result);
		$this->load->view("home/submitted_assess", $result);
	}


	function base64EncodeImage($image_file)
	{
		$base64_image = '';
		$image_info = getimagesize($image_file);
		$image_data = fread(fopen($image_file, 'r'), filesize($image_file));
		$base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data));
		return $base64_image;
	}


	// 0426教师信息搜索
	function getTeatcherList()
	{
		$this->load->model('Admin_model');
		$connar['where'] = $this->sqlLikeEscape('status=?? and (username like "%??%" or usercode like "%??%" ) and role_id=??', array(CommonStatus::UnDeleted[XPHEnum::Value], $_POST['teacher_name'], $_POST['teacher_code'], WebRole::Teacher[XPHEnum::Value]));
		$data = $this->Admin_model->get_single_full($connar);

		$data['title'] = (new Title)->show($data['title']);
		$data['teachers_attribute'] = (new TeachersAttribute)->show($data['teachers_attribute']);

		// pri($data);
		exit(retJson('返回搜索结果', true, $data));
	}


	// 0507课程信息搜索
	function getClassList()
	{
		$teacher_code = $_POST['teacher_code'];

		$data = $this->getClass($teacher_code);


		// pri($data);

		exit(retJson('返回搜索结果', true, $data));
	}


	function getClass($teacher_code)
	{
		$this->load->model("Class_model");
		// $month = date('m', time());
		if ($this->month == 9 || $this->month == 10 || $this->month == 11 || $this->month == 12 || $this->month == 1) {
			if ($this->month == 1) {
				$year = date('Y', time()) - 1;
				$year_last = date('Y', time());
			} else {
				$year = date('Y', time());
				$year_last = date('Y', time()) + 1;
			}
			// $year=date('Y',time());
			// $year_last=date('Y',time())+1;
			$default_academic_year = strval($year . '-' . $year_last).'-1';
		} else if ($this->month == 2 || $this->month == 3 || $this->month == 4 || $this->month == 5 || $this->month == 6 || $this->month == 7 || $this->month == 8) {
			$year = date('Y', time()) - 1;
			$year_last = date('Y', time());
			$default_academic_year = strval($year . '-' . $year_last).'-2';
		}

		$connar['where'] = 'db_class.elective_lesson_no like "%' . $default_academic_year . '%"';

		if (isset($teacher_code)) {
			$connar['where'] .= 'and db_class.teacher_id like "%' . $teacher_code . '%"';
		}


		$connar['join'] = array('db_admin', 'db_admin.usercode=db_class.teacher_id');
		$connar['items'] = "name,db_class.id,username,db_admin.dept_name,db_class.classroom,db_class.classname";
		$connar['groupby'] = "db_class.id";
		$data = $this->Class_model->get_list_full($connar);
		foreach ($data as $k => $v) {
			if (!$v['username']) {
				$data[$k]['username'] = '';
			}
			if (!$v['dept_name']) {
				$data[$k]['dept_name'] = '';
			} else {
				$data[$k]['dept_name'] =  $v['dept_name'];
			}
			$data[$k]['classroom'] = $v['classroom']?explode(';', $v['classroom'])[0]:'无';
			$data[$k]['classname'] = $v['classname']?explode(';', $v['classname'])[0]:'无';
		}
		return  $data;
	}


	function checkClass()
	{
		// $date = date('Y-m-d', time());
		// $month = date('m', time());
		if ($this->month == 9 || $this->month == 10 || $this->month == 11 || $this->month == 12 || $this->month == 1) {
			if ($this->month == 1) {
				$year = date('Y', time()) - 1;
				$year_last = date('Y', time());
			} else {
				$year = date('Y', time());
				$year_last = date('Y', time()) + 1;
			}
			// $year=date('Y',time());
			// $year_last=date('Y',time())+1;
			$default_academic_year = strval($year . '-' . $year_last);
		} else if ($this->month == 2 || $this->month == 3 || $this->month == 4 || $this->month == 5 || $this->month == 6 || $this->month == 7 || $this->month == 8) {
			$year = date('Y', time()) - 1;
			$year_last = date('Y', time());
			$default_academic_year = strval($year . '-' . $year_last);
		}
		// 获取教师
		$connar['where'] = $this->sqlLikeEscape('elective_lesson_no like "%??%" and name="??" and teacher_id like "%??%" and classname="??" ', array($default_academic_year, $_POST['name'], $_POST['teacher_id'], $_POST['classname']));
		$data = $this->Class_model->get_single_full($connar);
		if ($data) {
			exit(retJson("查询成功", true, $data));
		} else {
			exit(retJson("不存在该课程", false));
		}
	}


	// 0507 课程信息session保存
	function setClass()
	{
		$this->load->model("Class_model");
		if (isset($_POST['class_name'])) {
			$arraylist = array();
			// var_dump($_POST['class_id']);
			if (isset($_POST['teacher_code']) && (isset($_POST['class_id']) && $_POST['class_id'] != '无') ) {
				// $month = date('m', time());
				if ($this->month == 9 || $this->month == 10 || $this->month == 11 || $this->month == 12 || $this->month == 1) {
					if ($this->month == 1) {
						$year = date('Y', time()) - 1;
						$year_last = date('Y', time());
					} else {
						$year = date('Y', time());
						$year_last = date('Y', time()) + 1;
					}
					// $year=date('Y',time());
					// $year_last=date('Y',time())+1;
					$default_academic_year = strval($year . '-' . $year_last);
				} else if ($this->month == 2 || $this->month == 3 || $this->month == 4 || $this->month == 5 || $this->month == 6 || $this->month == 7 || $this->month == 8) {
					$year = date('Y', time()) - 1;
					$year_last = date('Y', time());
					$default_academic_year = strval($year . '-' . $year_last);
				}
				// $connar['where'] = $this->sqlLikeEscape('name like "%??%" and elective_lesson_no like "%??%" and teacher_id like "%??%"', array($_POST['class_name'], $default_academic_year, $_POST['teacher_code']));
				$connar['where'] = $this->sqlLikeEscape('id = ?? and elective_lesson_no like "%??%" and teacher_id like "%??%"', array($_POST['class_id'], $default_academic_year, $_POST['teacher_code']));
				$data = $this->Class_model->get_single_full($connar);

				if ($data) {			
					$arraylist['class_id'] = $data['id'];
					$arraylist['classtype'] = $data['type'];
					$arraylist['classname'] = $data['classname'];
					$arraylist['course_units'] = $data['course_units'];
					// var_dump($data['classroom']);
					if ($data['classroom']) {
						$arraylist['classroom'] = explode(';', $data['classroom'])[0];
					}
				}
				// var_dump($data);
			}
			exit(retJson('返回数据', true, $arraylist));
		} else {
			exit(retJson('系统错误', false));
		}
	}


    public function rebackAll()
    {
        if (!isset($_POST['id'])) {
            exit(retJson('参数错误', false));
        }


        $ids =  implode(',', $_POST['id']);
//听课
        $connar['where'] = "id in(" . $ids . ")";
        $connar['orderby'] = 'FIELD(id,'.$ids.')';
        $attendArr = $this->Attend_model->get_list_full($connar);

        foreach ($attendArr as $attend){
                if($attend['status'] != 2)continue;

            $this->Attend_model->update(array('id' => $attend['id'], 'status' => 1,'back_time'=>time(),'back_remark'=>'批量退回'));
        }



        exit(retJson("退回成功.", true));
//         echo $this->db->last_query();exit;
//        exit(retJson("提交成功.", true));
    }
}
